package com.yjhb.android.sbz.adapter;

import android.content.Context;
import androidx.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.yjhb.android.sbz.R;
import com.yjhb.android.sbz.entity.Order;
import com.jojo.android.zxlib.base.BaseListAdapter;
import com.jojo.android.zxlib.tool.ZxTimeTool;
import com.jojo.android.zxlib.view.CircleImageView;

/**
 * 创建者 zx
 * 创建时间 2020/12/4 9:42
 */
public class RechargeHistoryAdapter extends BaseListAdapter<Order> {
    private final String TAG = "RechargeHistoryAdapter";

    public RechargeHistoryAdapter(Context context) {
        super(context);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        try {
            RechargeHistoryHolder rechargeHistoryHolder = null;
            if (convertView == null) {
                convertView = LayoutInflater.from(context).
                        inflate(R.layout.item_recharge_history, null, false);
                convertView.setTag(new RechargeHistoryHolder(convertView));
            }
            rechargeHistoryHolder = (RechargeHistoryHolder) convertView.getTag();
            Order history = data.get(position);
            rechargeHistoryHolder.date_tv.setText(ZxTimeTool.simpleDateFormat("MM-dd HH:mm", history.getCreateTime()));
            rechargeHistoryHolder.id_tv.setText("订单编号：" + history.getOrderId());
            rechargeHistoryHolder.money_tv.setText("+" + history.getMoney() + "元");
            int imgid = 0;
            switch (history.getSource()) {
                case 10:
                    imgid = R.mipmap.weixin;
                    break;
                case 11:
                    imgid = R.mipmap.zfb;
                    break;
            }
            Glide.with(context).load(imgid).apply(new RequestOptions().placeholder(R.mipmap.logo)).into(rechargeHistoryHolder.image_iv);
            switch (history.getStatus()) {
                case 1:
                    rechargeHistoryHolder.title_tv.setText("订单处理中");
                    break;
                case 2:
                    rechargeHistoryHolder.title_tv.setText("充值成功");
                    break;
                case 3:
                    rechargeHistoryHolder.title_tv.setText("订单已取消");
                    break;
                default:
                    rechargeHistoryHolder.title_tv.setText("");
            }
        } catch (Exception e) {
        }
        return convertView;
    }

    class RechargeHistoryHolder {

        CircleImageView image_iv;
        TextView title_tv;
        TextView money_tv;
        TextView id_tv;
        TextView date_tv;
        View itemView;

        public RechargeHistoryHolder(@NonNull View itemView) {
            this.itemView = itemView;
            image_iv = itemView.findViewById(R.id.image_iv);
            title_tv = itemView.findViewById(R.id.title_tv);
            money_tv = itemView.findViewById(R.id.money_tv);
            id_tv = itemView.findViewById(R.id.id_tv);
            date_tv = itemView.findViewById(R.id.date_tv);
        }
    }

}
